﻿#ifndef __SS_MESH_RENDER_H__
#define __SS_MESH_RENDER_H__
#include "../ssComponent.h"
#include "../../shader/ssShaderAttrib.h"
#include "../../opengl/vbo/ssBOBind.h"
#include "../../resmgr/ssMesh.h"


//顶点数据和效果
#define SS_VDF_VERTEX_3F		1	//启用顶点数组
#define SS_VDF_INDEX			2	//启用顶点索引数组
#define SS_VDF_COLOR_4F			4	//启用颜色数组
#define SS_VDF_TEXCOORD_2F		8	//启用二维纹理坐标数组
#define SS_VDF_NORMAL_3F		16	//启用顶点法线数组
#define SS_VDF_TANGENT_3F		32	//启用顶点切线数组
#define SS_ES_ALPHA				64	//启用阿尔法透明
//渲染队列分类
#define SS_QUE_BACKGROUND		1000
#define SS_QUE_TERRAIN			1500
#define SS_QUE_GEOMERY			2000
#define SS_QUE_ALPHA			2500
#define SS_QUE_TRANSPARENT		3000
#define SS_QUE_OVERLAY			4000


namespace StarSeeker
{

class ssMeshRender : public ssComponent
{
	friend class ssRenderSystem;
public:
	ssMeshRender();
	virtual ~ssMeshRender();

	//设置顶点数据
	bool SetVertex(u32 num, const ssfloat* pv);
	//设置索引数据
	bool SetIndex(u32 num, const void* pi, u32 bit = SS_INDEX_16);
	//设置法线
	bool SetNormal(u32 num, const ssfloat* pn);
	//设置切线
	bool SetTangent(u32 num, const ssfloat* pt);
	//使用模型对象设置渲染数据
	virtual void SetDataFromMesh(const char* uri);
	//设置效果开关
	void SetVDF(u32 es);

public:
	//内部调用
	virtual void OnRenderBegin();
	virtual void OnRenderEnd();
	virtual void Render();

protected:
	u32						m_VDF;				//顶点数据格式
	ssIBOBind*				m_index;			//顶点索引
	ssVBOBind*				m_vertex;			//顶点数据
	ssShaderAttribute		m_vertexAttrib;
	ssVBOBind*				m_normal;			//顶点法线
	ssShaderAttribute		m_normalAttrib;
	ssVBOBind*				m_tangent;			//顶点切线
	ssShaderAttribute		m_tangentAttrib;
	u32						m_primitiveType;	//图元类型
	ssMesh*					m_pMesh;
	u32						m_queTag;			//渲染队列标记
	u32						m_distance;			//用于渲染排序
};

}
#endif
